Conversation
| if (result != 5) | ||
| { | ||
| throw new InvalidOperationException($"Expected 5, but got {result}"); | ||
| } |
There was a problem hiding this comment.
Если уж Вы заморочились и написали настоящие тесты, то можно было дополнительно заморочиться и написать свой Assert.
| public void Calculator_Divide_ByZero_ShouldThrow() | ||
| { | ||
| Calculator.Divide(10, 0); | ||
| } |
There was a problem hiding this comment.
И можно более активно использовать =>
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="StyleCop.Analyzers" Version="1.1.118"> |
There was a problem hiding this comment.
StyleCop староват, надо 1.2-beta. Иначе он нового C# не знает
| Assert.That(testResult.Exception, Is.Not.Null); | ||
| }); | ||
| } | ||
| } |
There was a problem hiding this comment.
Надо ещё проверить на ситуацию, когда исключение ожидалось, но не брошено, на то, что вызываются Before/After и т.д., и на исключения в них.
| /// Gets the reason why the test is ignored. | ||
| /// </summary> | ||
| public string Reason { get; } | ||
| } |
There was a problem hiding this comment.
Ignore просили просто как строковое свойство у атрибута Test, но окей, так тоже сойдёт, можно не править
| /// Gets exception thrown by test. | ||
| /// </summary> | ||
| public Exception? Exception { get; init; } | ||
| } |
There was a problem hiding this comment.
Тут лучше бы подошёл record с позиционными свойствами. То же самое, но в разы короче писать.
| /// <summary> | ||
| /// Test failed. | ||
| /// </summary> | ||
| Failed, |
There was a problem hiding this comment.
Лучше различать Failed (не прошёл сам тест) и Errored (не прошёл один из вспомогательных методов, типа BeforeClass, так что с самим тестом, может, всё и ок).
| /// Test was ignored. | ||
| /// </summary> | ||
| Ignored, | ||
| } No newline at end of file |
There was a problem hiding this comment.
И опять-таки, правильнее держать каждый тип в своём файле. Так проще ориентироваться в проекте.
| { | ||
| InvokeStatic(beforeClass); | ||
|
|
||
| foreach (var test in tests) |
There was a problem hiding this comment.
Так получается, что если усть одна сборка с одним классом и тысячей тестов в нём, ничего не выполняется параллельно.
| } | ||
| finally | ||
| { | ||
| InvokeStatic(afterClass); |
There was a problem hiding this comment.
afterClass тоже может бросить исключение, и в этом случае все тесты в классе тоже надо пометить как Errored, даже если они прошли.
No description provided.